<template>
    <div>
        <div id="editor">
            <div v-html="editorHtml"></div>
        </div>
    </div>
</template>
<script>
import WangEditor from 'wangeditor'
// import request from '@/utils/request'
export default {
  props: {
    editorHtml: String
  },
  mounted() {
    this.editor = new WangEditor('#editor')
    this.editor.customConfig.onchange = (html) => {
      this.$emit('getEditorCon', this.editor)
    }
    this.editor.customConfig.uploadFileName = 'files2'
    this.editor.customConfig.uploadImgServer = '/api/file/uploadImg' // 显示"上传图片"tab，上传图片到服务器
    // this.editor.customConfig.uploadImgServer = request.post('/file/uploadImg')
    this.editor.customConfig.showLinkImg = false // 隐藏“网络图片”tab
    this.editor.customConfig.uploadImgHooks = { // 使用监听函数在上传图片的不同阶段做相应的处理
      customInsert: (insertImg, result, editor) => { // 图片上传成功之后触发，result是服务器返回的结果
        if (result.code === 0) {
          insertImg(result.content)
        } else {
          alert(result.content)
        }
      }
    }
    this.editor.create()
  },
  data() {
    return {
      editor: {}
    }
  }
}
</script>
